﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace Proggy.Web.Cms.Core.Configuration
{
    /// <summary>
    /// Defines part element collection
    /// </summary>
    public class DragAndDropPartElementCollection : ConfigurationElementCollection
    {
        public DragAndDropPartElementCollection() { }

        public override ConfigurationElementCollectionType CollectionType
        {
            get
            {
                return ConfigurationElementCollectionType.AddRemoveClearMap;
            }
        }

        public DragAndDropPartElement this [ int index ]
        {
            get { return ( DragAndDropPartElement ) base.BaseGet( index ); }
        }

        public new DragAndDropPartElement this [ string name ]
        {
            get
            {
                DragAndDropPartElement output = ( DragAndDropPartElement ) base.BaseGet( name );

                //if (
                //    ( string.IsNullOrEmpty(output.ControllerName) && !string.IsNullOrEmpty(output.BusinessObjectClassName) ) ||
                //    ( !string.IsNullOrEmpty( output.ControllerName ) && string.IsNullOrEmpty( output.BusinessObjectClassName ) )
                //    )
                //{
                //    throw new Exception( "In the web.config file \"IntranetPageParts\" section, the part \"" + output.Name +
                //        "\"  has either a controller or a business object - it can have only neither, or both." );
                //}
                //else
                //{
                //    return output;
                //}

                return output;
            }
        }

        protected override ConfigurationElement CreateNewElement()
        {
            return new DragAndDropPartElement();
        }

        protected override object GetElementKey( ConfigurationElement element )
        {
            return ( ( DragAndDropPartElement ) element ).Name;
        }

        public int IndexOf( DragAndDropPartElement part )
        {
            return BaseIndexOf( part );
        }

        public void Add( DragAndDropPartElement part )
        {
            BaseAdd( part );
        }

        public void Remove( DragAndDropPartElement part )
        {
            if ( BaseIndexOf( part ) > 0 )
            {
                BaseRemove( part.Name );
            }
        }

        public void RemoveAt( int index )
        {
            BaseRemoveAt( index );
        }

        public void Remove( string name )
        {
            BaseRemove( name );
        }

        public void Clear()
        {
            BaseClear();
        }
    }
}
